# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=dumb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.3
pkgrel=1
pkgdesc="IT, XM, S3M and MOD player library (mingw-w64)"
arch=('any')
url="http://dumb.sourceforge.net/"
license=("custom:dumb, GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-allegro"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-ninja")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/kode54/dumb/archive/${pkgver}.tar.gz")
sha256sums=('99bfac926aeb8d476562303312d9f47fd05b43803050cd889b44da34a9b2a4f9')

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  
  # Shared Build
  [[ -d "${srcdir}"/build-${CARCH}-shared ]] && rm -rf "${srcdir}"/build-${CARCH}-shared
  mkdir -p "${srcdir}"/build-${CARCH}-shared && cd "${srcdir}"/build-${CARCH}-shared
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'Ninja' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_INSTALL_LIBDIR=lib \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=ON \
      -DBUILD_ALLEGRO4=OFF \
      -DBUILD_EXAMPLES=OFF \
      ../${_realname}-${pkgver}
  ${MINGW_PREFIX}/bin/ninja
  
  # Static Build
  [[ -d "${srcdir}"/build-${CARCH}-static ]] && rm -rf "${srcdir}"/build-${CARCH}-static
  mkdir -p "${srcdir}"/build-${CARCH}-static && cd "${srcdir}"/build-${CARCH}-static
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'Ninja' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_INSTALL_LIBDIR=lib \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=OFF \
      -DBUILD_ALLEGRO4=OFF \
      -DBUILD_EXAMPLES=OFF \
      ../${_realname}-${pkgver}
  ${MINGW_PREFIX}/bin/ninja
}

package() {
  # Shared Install
  cd "${srcdir}"/build-${CARCH}-shared
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja install
  
  # Static Install
  cd "${srcdir}"/build-${CARCH}-static
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja install
  
  # License
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
